package com.林子祺.CAT旅游系统.view;

import com.林子祺.CAT旅游系统.controller.contentmanagement.RecommendShow;
import com.林子祺.CAT旅游系统.controller.contentmanagement.ShowContent;
import com.林子祺.CAT旅游系统.controller.contentmanagement.ShowOrderedTicket;
import com.林子祺.CAT旅游系统.controller.login.MenuLogin;
import com.林子祺.CAT旅游系统.controller.login.MenuLogout;
import com.林子祺.CAT旅游系统.dao.placemanagement.PlacePull;
import com.林子祺.CAT旅游系统.dao.ticketmanagement.TicketPull;
import com.林子祺.CAT旅游系统.dao.ticketmanagement.TicketPull3;
import com.林子祺.CAT旅游系统.entity.login.LoginStatus;
import com.林子祺.CAT旅游系统.entity.place.PlaceData;
import com.林子祺.CAT旅游系统.entity.ticket.TicketData;
import com.林子祺.CAT旅游系统.view.tour.admin.AdminMenu;
import com.林子祺.CAT旅游系统.view.tour.buy.BuyTicket;
import com.林子祺.CAT旅游系统.view.tour.buy.ChargeMoney;
import com.林子祺.CAT旅游系统.view.tour.buy.DeleteBuyTicket;
import com.林子祺.CAT旅游系统.view.tour.buy.SearchTicket;
import com.林子祺.CAT旅游系统.view.tour.search.SearchTable;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import static java.lang.System.exit;

public class Menu {

    static int number = 0;
    static int t = 1;

    public static void menu() throws AWTException {

        JFrame jf = new JFrame("欢迎使用CAT旅游系统");
        jf.setSize(450, 450);
        jf.setLocationRelativeTo(null);
        jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

        JPanel panel = new JPanel(null);


        JLabel label01 = new JLabel();
            if (LoginStatus.loginY_N) {
                if (LoginStatus.admin)
                    label01.setText("旅游系统  你好：管理员" );
                else
                    label01.setText("旅游系统  你好：" + LoginStatus.name);
            } else
                label01.setText("登陆界面  你好：游客");
            label01.setLocation(0,0);
            label01.setSize(200,25);
            label01.setFont(new Font(null, Font.PLAIN, 15));
            panel.add(label01);

        JLabel label02 = new JLabel();
        label02.setText("账户所剩余额为："+LoginStatus.money);
        label02.setLocation(0,30);
        label02.setSize(200,20);
        label02.setFont(new Font(null, Font.PLAIN, 10));
        if(LoginStatus.loginY_N) {
            panel.add(label02);
        }

            final JButton btn = new JButton("登录");
            btn.setLocation(240,0);
            btn.setSize(60,25);
            btn.setFont(new Font(null, Font.PLAIN, 10));
            final JButton btn1 = new JButton("退出登录");
            btn1.setLocation(300,0);
            btn1.setSize(75,25);
            btn1.setFont(new Font(null, Font.PLAIN, 10));
            final JButton btn2 = new JButton("退出");
            btn2.setLocation(375,0);
            btn2.setSize(60,25);
            btn2.setFont(new Font(null, Font.PLAIN, 10));
            final JButton btn3 = new JButton("今日推荐");
            btn3.setLocation(150,50);
            btn3.setSize(150,40);
            btn3.setFont(new Font(null, Font.PLAIN, 17));
            final JButton btn4 = new JButton("景点查询");
            btn4.setLocation(150,120);
            btn4.setSize(150,40);
            btn4.setFont(new Font(null, Font.PLAIN, 17));
            final JButton btn5 = new JButton("模糊查询");
            btn5.setLocation(150,190);
            btn5.setSize(150,40);
            btn5.setFont(new Font(null, Font.PLAIN, 17));
            final JButton btn6 = new JButton("充值");
            btn6.setLocation(240,25);
            btn6.setSize(60,25);
            btn6.setFont(new Font(null, Font.PLAIN, 10));
            final JButton btn7 = new JButton("门票查询");
            btn7.setLocation(150,260);
            btn7.setSize(150,40);
            btn7.setFont(new Font(null, Font.PLAIN, 17));
            final JButton btn8 = new JButton("门票购买");
            btn8.setLocation(150,330);
            btn8.setSize(150,40);
            btn8.setFont(new Font(null, Font.PLAIN, 17));
            final JButton btn9 = new JButton("购买历史");
            btn9.setLocation(0,45);
            btn9.setSize(75,25);
            btn9.setFont(new Font(null, Font.PLAIN, 10));
            final JButton btn10 = new JButton("管理员模式");
            btn10.setLocation(0,45);
            btn10.setSize(100,25);
            btn10.setFont(new Font(null, Font.PLAIN, 10));
            final JButton btn11 = new JButton("退票");
            btn11.setLocation(0,70);
            btn11.setSize(75,25);
            btn11.setFont(new Font(null, Font.PLAIN, 10));



            // 添加按钮的点击事件监听器
            btn.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    // 获取到的事件源就是按钮本身
                    // JButton btn = (JButton) e.getSource();
                    try {
                        MenuLogin.login();
                        jf.dispose();
                    } catch (Exception exception) {
                        exception.printStackTrace();
                    }
                }
            });

            btn1.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    // 获取到的事件源就是按钮本身
                    // JButton btn = (JButton) e.getSource();
                    MenuLogout.logout();
                    jf.dispose();
                    try {
                        menu();
                    } catch (AWTException awtException) {
                        awtException.printStackTrace();
                    }
                }
            });

            btn2.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    // 获取到的事件源就是按钮本身
                    // JButton btn = (JButton) e.getSource();

                    exit(1);
                }
            });

        btn3.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                RecommendShow.get();
                jf.dispose();
            }
        });

        btn4.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                // 获取到的事件源就是按钮本身
                // JButton btn = (JButton) e.getSource();

                ShowContent.show();
                jf.dispose();
            }
        });

        btn5.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                // 获取到的事件源就是按钮本身
                // JButton btn = (JButton) e.getSource();

                SearchTable.search();
                jf.dispose();
            }
        });

        btn6.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                ChargeMoney.charge();
                jf.dispose();
            }
        });

        btn7.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                PlaceData.Refresh();
                PlacePull.pull();
                SearchTicket.search();
                jf.dispose();
            }
        });

        btn8.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                BuyTicket.buy();
                jf.dispose();
            }
        });

        btn9.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                ShowOrderedTicket.show(LoginStatus.name);
                jf.dispose();
            }
        });

        btn10.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                AdminMenu.menu();
                jf.dispose();
            }
        });

        btn11.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                TicketData.Refresh();
                TicketPull3.pull(LoginStatus.name);
                DeleteBuyTicket.change();
                jf.dispose();
            }
        });

            panel.add(btn);
            panel.add(btn1);
            panel.add(btn2);
            panel.add(btn3);
            panel.add(btn4);
            panel.add(btn5);
        if(LoginStatus.loginY_N){
            if(LoginStatus.admin == false){
                panel.add(btn6);
                panel.add(btn8);
                panel.add(btn9);
                panel.add(btn11);
            }
            else
                panel.add(btn10);
        }
            panel.add(btn7);

            jf.setContentPane(panel);
            jf.setVisible(true);
        }
    }

